//
//  MainWindow.swift
//  AutoModel
//
//  Created by 好米有易 on 2019/9/11.
//  Copyright © 2019 own. All rights reserved.
//

import Cocoa
import SnapKit

class MainWindowController: NSWindowController {

    @IBOutlet weak var searchItem: NSToolbarItem!
    @IBOutlet weak var segementItem: NSToolbarItem!
    @IBOutlet weak var addItem: NSToolbarItem!
    @IBOutlet weak var toolbar: NSToolbar!

    lazy var apiRequestView: ApirequestView = {
        let apiRequestView = ApirequestView()
        return apiRequestView
    }()

    override func windowDidLoad() {
        super.windowDidLoad()

        self.window?.minSize = MIN_SIZE

        addItem.target = self
        addItem.minSize = NSSize(width: 30, height: 25)
        addItem.action = #selector(addAction)

        segementItem.target = self
        segementItem.action = #selector(choseModelLanguage)

        searchItem.target = self
        searchItem.action = #selector(searchAction)
    }

}


// MARK: - action
extension MainWindowController {
    @objc func addAction() {
        let alert = NSAlert()
        alert.messageText = "1322222222";
        alert.alertStyle = .critical
        alert.accessoryView = self.apiRequestView
        alert.addButton(withTitle: "确定")
        alert.addButton(withTitle: "取消")
        print(alert.buttons)
        alert.beginSheetModal(for: self.window!) { (code) in
            print("--------------------------")
            if code == .alertFirstButtonReturn {
                print("12341")
                guard let vc: ViewController = self.contentViewController as? ViewController else { return }
                guard let type = RequstType(rawValue: self.apiRequestView.requestType) else { return }

                print(type)
                print(vc)
                vc.request(type: type, url: self.apiRequestView.url, paraters: nil)
            }
        }
    }

    @objc func choseModelLanguage() {

        print("choseModelLanguage")
    }

    @objc func searchAction() {

        print("searchAction")
    }

}
